home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / AppleScript / Development Tools / Tools Goodies / AEGizmos 1.4.1 / Documentation / AE Sub-descriptor Doc.dp (.txt) < prev    next >
Encoding:
Common Ground  |  1995-03-20  |  27.8 KB  |  378 lines  |  [CGDC/CGVM]

  1. TCGDC
  2. Palatino
  3. Apple Events
  4.  Sub-Descriptors
  5. AEGizmos Version 1.4
  6. Jens Peter Alfke
  7. 20 March 1995
  8.  Apple Computer, Inc. 1991
  9. New York
  10. Palatino
  11. Apple Event Sub-Descriptors
  12. 3/20/95
  13. Page 
  14. Introduction
  15. OK, What Is It?
  16. NThis library provides a high-efficiency way to examine and take apart (but not
  17. !modify) Apple Event descriptors (
  18. Courier
  19. AEDesc
  20. )$' structures). Almost everything is done
  21. fOin place, without any copying of data, which avoids most of the overhead of the
  22. KApple Event Manager. However, the API is very  similar to that of the Apple
  23. 8Event Manager, which makes it easy to convert your code.
  24. K(Why are these functions read-only? Only one copy of the descriptor data is
  25. Ostored, and descriptors within the main one are represented by offsets into the
  26. Kdata. Changing one sub-descriptor would often involve inserting or deleting
  27. Kdata, which would invalidate the offsets of all following sub-descriptors.)
  28. s In It For Me?
  29. >Speed, speed, speed 
  30. with very little of your code to modify.
  31. NParsing complex nested Apple event descriptors (such as the object descriptors
  32. Mused by the Apple Event Object Model) involves copying lots and lots of data.
  33. "For instance, every time you call 
  34. AEGetNthDesc
  35. )H% to get an element out of a list, all
  36. fUthe data of that element (and of any descriptors nested within it, if it
  37. s also an ar
  38. f+ray or record) is copied into a new handle.
  39. OThe functions in the 
  40. SubDescs library provide an interface that
  41. s very similar
  42. Kto a subset of that provided by the Apple Event Manager. (You should have a
  43. Opretty easy job converting your code to use the library.) However, when you use
  44. Wits routines to extract a nested descriptor, it doesn
  45. t copy the data. Instead, it just
  46. Qmakes a new descriptor that contains a (long integer) offset into the original de
  47. fTscriptor
  48. s data. The only time taken is that to find the location of the sub-descrip
  49. tor in the data.
  50. Palatino
  51. The AppleEvent Stream Library
  52. Page 
  53. 3/20/95
  54. s New?
  55. In version 1.4:
  56. Eyou can now create sub-descriptors on complete Apple events! An Apple
  57. Fevent works like a record, where the items are the event
  58. s parameters.
  59. JAESubDescToDesc now properly copies the entire descriptor when the type is
  60. DtypeWildCard and the sub-descriptor is the same as the whole AEDesc.
  61. >Added AECopySubDescData at Dave Shaver's suggestion: it
  62. s like
  63. EAEGetSubDescData but copies the data rather than just pointing to it.
  64. Palatino
  65. The AppleEvent Stream Library
  66. 3/20/95
  67. Page 
  68. !The Sub-Descriptor Data Structure
  69. f1The new data structure involved is the AESubDesc:
  70. Courier
  71. typedef struct {
  72. DescType
  73. subDescType;
  74. Handle
  75. dataHandle;
  76. offset;
  77. } AESubDesc;
  78.     AESubDesc
  79. )6? represents an Apple Event descriptor nested within an existing
  80. descriptor (
  81. AEDesc
  82. )$3). It contains a handle to some data 
  83.  which is the
  84. .dataHandle
  85.  of the existing 
  86. AEDesc
  87.  as well as an offset into that descriptor's
  88. fPdata. The offset points to the beginning of the nested sub-descriptor within the
  89.     main one.
  90. NThis way, when working with a lot of sub-descriptors of a main descriptor it's
  91. 8only offsets that are moved around, not the actual data.
  92. Palatino
  93. The AppleEvent Stream Library
  94. Page 
  95. 3/20/95
  96. The Sub-Descriptor Functions
  97. NITIALIZATION
  98. AEDescToSubDesc
  99. Courier
  100. pascal OSErr
  101. 4AEDescToSubDesc( const AEDesc*, AESubDesc* result );
  102. ?This is how you begin. Given a regular Apple Event descriptor, 
  103. AEDescToSubDesc
  104. NIsets up a sub-descriptor that starts out pointing to the main descriptor.
  105. CCESSING
  106. AEGetSubDescType
  107. pascal DescType
  108. %AEGetSubDescType( const AESubDesc* );
  109. AEGetSubDescType
  110. )`+ returns the type code of a sub-descriptor.
  111. Zapf Dingbats
  112. :If you want, you can also get this type directly from the 
  113. .subDescType
  114. field of the sub-descrip
  115. tor. Do 
  116.  modify this field!
  117. Palatino
  118. The AppleEvent Stream Library
  119. 3/20/95
  120. Page 
  121. AEGetSubDescBasicType
  122. Courier
  123. pascal OSErr
  124. ?AEGetSubDescBasicType( const AESubDesc*, DescType *basicType );
  125. AEGetSubDescBasicType
  126.  is the same as 
  127. AEGetSubDescType
  128. , with one exception: if
  129. fIthe sub-descriptor is a coerced record, the type returned is typeAERecord
  130. 'reco'
  131. AEGetSubDescIsListOrRecord
  132. pascal Boolean
  133. .AESubDescIsListOrRecord( const AESubDesc* sd )
  134. AESubDescIsListOrRecord
  135. 6 returns true if the given sub-descriptor is a list, a
  136. record, 
  137. or a coerced record
  138. AEGetSubDescData
  139. pascal void*
  140. 3AEGetSubDescData( const AESubDesc*, long *length );
  141. AEGetSubDescData
  142. )`@ returns a pointer to the data of a sub-descriptor, and sets the
  143. length
  144. )$6 parameter equal to the length of the data (in bytes.)
  145. f#If the descriptor has no data (its 
  146. dataHandle
  147. ) then 
  148.  will be returned
  149. and the 
  150. length
  151.  parameter will be set to zero.
  152. Zapf Dingbats
  153. Warning
  154. )D@Note that the pointer points within the descriptor's data handle
  155. .dataHandle
  156. )B2) and will become invalid if that handle is moved,
  157. ?purged or disposed as a result of a Memory Manager call. If you
  158. want, you can lock the 
  159. dataHandle
  160. )<" before this call, and restore its
  161. Aprevious state later. Remember that all sub-descriptors retrieved
  162. from a single 
  163. AEDesc
  164.  share the same data handle!
  165. Palatino
  166. The AppleEvent Stream Library
  167. Page 
  168. 3/20/95
  169. AECopySubDescData
  170. Courier
  171. pascal void
  172. RAECopySubDescData( const AESubDesc*, long *length, const void *dst, long maxLen );
  173. AEGetSubDescData
  174. )`? copies the data of a sub-descriptor to the data buffer pointed
  175. to by 
  176. , and sets the 
  177. length
  178. )$6 parameter equal to the length of the data (in bytes.)
  179. N$However, it will not copy more than 
  180. maxLen
  181. )$( bytes to the buffer, even if the actual
  182. length is greater.
  183. #If the descriptor has no data (its 
  184. dataHandle
  185. ) then no data will be copied
  186. and the 
  187. length
  188.  parameter will be set to zero.
  189. AESubDescToDesc
  190. pascal OSErr
  191. JAESubDescToDesc( const AESubDesc*, DescType desiredType, AEDesc* result );
  192. AESubDescToDesc
  193. )Z= copies a sub-descriptor into a brand new Apple event descrip
  194. NJtor. (This calls the Memory  Manager and may move or purge memory blocks.)
  195. OThe resulting descriptor will be coerced to the desired type; if you don't want
  196. any coercion, use 
  197. typeWildCard
  198. '****'
  199. ) as the desired type.
  200.     CCESSING 
  201. RRAYS AND 
  202. ECORDS
  203. NQThese calls are now safe: when passed descriptors that are not lists or (possibly
  204. -coerced) records, they return the error code 
  205. errAEWrongDataType
  206.  instead of
  207. N    crashing.
  208. RIn versions 1.3.5 and later, you can now use these calls on an entire Apple event.
  209. NThe Apple event looks like a record whose items are the event
  210. s parameters. As
  211. >with any record, the order of the items is essentially random.
  212. AECountSubDescItems
  213. pascal long
  214. (AECountSubDescItems( const AESubDesc* );
  215. Palatino
  216. The AppleEvent Stream Library
  217. 3/20/95
  218. Page 
  219. Courier
  220. AECountSubDescItems
  221. )r0 counts the number of items in a sub-descriptor.
  222. Zapf Dingbats
  223. )&=If an error occurs, the result returned will be a (negative) 
  224. OSErr
  225.  code
  226. >instead of a (non-negative) length. You should check for this.
  227. JCurrently the only way to get an error is to pass a descriptor that is not
  228. .a list, record, or coerced record; you
  229. ll get 
  230. errAEWrongDataType
  231.  back.
  232. AEGetNthSubDesc
  233. #define
  234. errAEListIsFactored
  235. -1760
  236. )6(// Can
  237. t get items out of factored lists
  238. pascal OSErr
  239. JAEGetNthSubDesc( const AESubDesc* source, long index, AESubDesc* result );
  240. AEGetNthSubDesc
  241. )ZA gets an item out of an array or record or Apple event, given its
  242. index. It sets up a new 
  243. )z    AESubDesc
  244. )61 structure to point to the item; only a few bytes
  245. of data are copied.
  246. It's okay if 
  247. source
  248.  and 
  249. result
  250. )$2 point to the same sub-descriptor; it will be over
  251. fOwritten with the new data. (This is not a memory leak since they share the same
  252. dataHandle
  253. VThis function will not work on factored lists; if the list is factored, the error code
  254. errAEListIsFactored
  255. )_( will be returned. (You could then call 
  256. AEGetSubDescData
  257.  to copy the list
  258. into a new 
  259. AEDesc
  260. # and then retrieve its items using 
  261. AEGetNthPtr
  262. AEGetNthDesc
  263. AEGetKeySubDesc
  264. pascal OSErr
  265. IAEGetKeySubDesc( const AESubDesc* source, AEKeyword, AESubDesc* result );
  266. AEGetKeySubDesc
  267. )Z= gets an item out of a (possibly coerced) record, given a key
  268. word. It sets up a new 
  269. )y    AESubDesc
  270. )61 structure to point to the item; only a few bytes
  271. of data are copied.
  272. It's okay if 
  273. source
  274.  and 
  275. result
  276. )$2 point to the same sub-descriptor; it will be over
  277. fOwritten with the new data. (This is not a memory leak since they share the same
  278. dataHandle
  279. Palatino
  280. The AppleEvent Stream Library
  281. Page 
  282. 3/20/95
  283. Zapf Dingbats
  284. ZThis function will not work on factored records; if the record is factored, the error code
  285. Courier
  286. errAEListIsFactored
  287. )_( will be returned. (You could then call 
  288. AEGetSubDescData
  289.  to copy the list
  290. into a new 
  291. AEDesc
  292. # and then retrieve its items using 
  293. AEGetKeyPtr
  294. AEGetKeyDesc
  295. Palatino
  296. The AppleEvent Stream Library
  297. 3/20/95
  298. Page 
  299. The Header File
  300. fKHere for your convenience is a printout of the .h file as of 17 March 1995.
  301. Courier
  302. // AESubDescs.h
  303. U// A high-efficiency way to examine AEDescs. Everything is done in place, without any
  304. Q// copying of data, which avoids most of the overhead of the Apple Event Manager.
  305. I// By Jens Alfke; Copyright 
  306. 1992-95 Apple Computer. All Rights Reserved.
  307. #pragma once
  308. #ifndef __AESUBDESCS__
  309. #define __AESUBDESCS__
  310. #ifndef __APPLEEVENTS__
  311. #include <AppleEvents.h>
  312. #endif
  313. enum{
  314. // Error code
  315. errAEListIsFactored
  316. = -1760
  317. )Z(// I cannot get data from factored lists
  318. struct AESubDesc {
  319. DescType
  320. subDescType;
  321. )H1// Type of this subDesc. You may read this field.
  322. Handle
  323. dataHandle;
  324. )H.// Handle to main (outer) descriptor. Private.
  325. offset;
  326. )H=// Offset into main descriptor where subDesc starts. Private.
  327. #typedef struct AESubDesc AESubDesc;
  328. #ifdef __cplusplus
  329. extern "C" {
  330. #endif
  331. pascal void
  332. -AEDescToSubDesc( const AEDesc*, AESubDesc* );
  333. Palatino
  334. The AppleEvent Stream Library
  335. Page 
  336. 3/20/95
  337. Courier
  338. pascal OSErr
  339. ?AESubDescToDesc( const AESubDesc*, long desiredType, AEDesc* );
  340. pascal DescType
  341. %AEGetSubDescType( const AESubDesc* );
  342. pascal void*
  343. CAEGetSubDescData( const AESubDesc*, long *length );dataHandle moves
  344. pascal void
  345. OAECopySubDescData( const AESubDesc *sd, long *length, void *dst, long maxLen );
  346. pascal Boolean
  347. /AESubDescIsListOrRecord( const AESubDesc* sd );
  348. pascal DescType
  349. *AEGetSubDescBasicType( const AESubDesc* );
  350. pascal long
  351. (AECountSubDescItems( const AESubDesc* );
  352. pascal OSErr
  353. 1AEGetNthSubDesc( const AESubDesc* sd, long index,
  354. ) AEKeyword* keyIfAny, AESubDesc* newSD ),
  355. r0AEGetKeySubDesc( const AESubDesc* sd, AEKeyword,
  356.  AESubDesc* newSD );
  357. #ifdef __cplusplus
  358. #endif
  359. #endif /*__AESUBDESCS__*/
  360. 6)3=*
  361. p 0p`P
  362. .!32/>
  363. $:7%95
  364.     temp.0001
  365. Tme:_
  366. Company:
  367. Cancel
  368. Jens Alfke
  369. Apple Computer
  370. Microsoft Word
  371. New York
  372. Zapf Dingbats
  373. Palatino
  374. Courier
  375. bPREC
  376. nPRVS
  377. zCAPN
  378.